﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataAccess_Layer
{
   public static class ChiTietLichSu_DAC
    {
       private static DataClasses_RetailerDataContext db = DataAccessHelper.DB;
        public static void insert(ChiTietLichSu cat)
        {
            db.ChiTietLichSus.InsertOnSubmit(cat);
            DataAccessHelper.Save();
        }

        public static void delete(List<long> deletedIDs)
        {
            foreach (long deletedID in deletedIDs)
            {
                ChiTietLichSu nccgh = DataAccessHelper.DB.ChiTietLichSus.Where(ncc => ncc.ID == deletedID).Select(ncc => ncc).First();
                DataAccessHelper.DB.ChiTietLichSus.DeleteOnSubmit(nccgh);
            }
            DataAccessHelper.Save();
        }

        public static void update(ChiTietLichSu nCC_GiangHang)
        {
            ChiTietLichSu ctls = DataAccessHelper.DB.ChiTietLichSus.Where(ncc => ncc.ID == nCC_GiangHang.ID).Select(ncc => ncc).First();
            ctls.ID = nCC_GiangHang.ID;
            ctls.IDLichSu = nCC_GiangHang.IDLichSu;
            ctls.TenSanpham = nCC_GiangHang.TenSanpham;
            ctls.SoLuong = nCC_GiangHang.SoLuong;
            ctls.GiaTien = nCC_GiangHang.GiaTien;
            ctls.ThanhTien = nCC_GiangHang.ThanhTien;     
      
            DataAccessHelper.Save();
        }

        public static object layHet()
        {
            return DataAccessHelper.DB.ChiTietLichSus.Select(cat => new { cat.ID, cat.IDLichSu, cat.TenSanpham, cat.SoLuong, cat.GiaTien, cat.ThanhTien });
        }
    }
}
